EVAL_ Command

does anyonf have any experience with the EVAL_ command? I was told that EVAL_ could be used within a DXL script to trigger the start of another DXL script.

Any help is greatly appreciated.

David Schwartz
SystemAdmin - Fri Aug 14 13:59:38 EDT 2009

Re: EVAL_ Command
llandale - Sun Aug 16 14:56:46 EDT 2009

Yes, you can send a script to eval_ and it will run it in its own context. 'Own Context' means the eval script will not have access to any of the main scripts variables nor functions; which likewise means you cannot pass in any sort of 'Module' et tal handle. If the eval DXL wants to deal with a module you'll need to pass that name in, and the eval script must open it.

When the eval DXL ends it will pass back to the main DXL the last string value of any 'return_' string used in the eval DXL. That 'return_' function does not mean 'stop now and return this string'; it means 'return this string when this DXL ends naturally'.

See below for a Demo. Notice that you need to escape double quotes in the string: "\"", as well as escape the slash character (not shown "\\"). Note my use of sibling 'checkDXL' which interprets the DXL (without actually running it) and traps typos before sending it off to run. Very useful.

Some of the real clever folks here may have found a use for eval_, but the only use I've found is for functions that use later versions of DXL features, such as the 'AttrDef' 'description' property: ad.description, which will generate DXL error when run in old DOORS versions. If I write a eval_ string to fetch the desription, I can trap and handle (in this case ignore) any DXL errors, and the code works for old versions.
 

  • Louie


Now there IS a use for 'evalTop_' which lets you put variables and functions in the DXL top context, making them available for other DXL programs to use. Haven't actually found a use for that, but surely there are some. Perhaps you want to overload the 'print' function such that instead of outputing to the DXL pane, it outputs it to a file.

 

 

// eval_ demo
/*
run from any current module,preferably one with deleted objects
*/
 
string    NameMod = fullName(current Module)
 
string  EvalCode =
"Module mod = read(\"" NameMod "\", false)
Object  obj
int     Count = 0
if (confirm(\"Count displayed objects only?\"))
{  for obj in mod do  Count++
   return_(\"Number Displayed objects = \" Count \"\")
}
else
{  for obj in entire mod do Count++
   return_(\"Number of All objects = \" Count \"\")
}
// close(mod) // Interesting, this will close the main open module
"  // end definition of string EvalCode
 
string ErrMess = checkDXL(EvalCode)
if (!null ErrMess)
{   print "Error in EvalCode ======\n" ErrMess 
   print "-------------\n" EvalCode "\n=============\n"
}
else
 
{  string Returned
   noError
   if (confirm("Introduce DXL Errors"))
        Returned = eval_("xx = yy\n" EvalCode)
   else Returned = eval_(EvalCode)
   ErrMess = lastError
   if (!null ErrMess)
        print "====ErrMess in EvalCode ===\n" ErrMess "=========\n"
   else print "Returned Code =========\n" Returned "\n=============\n"
 
}
// print "EvalCode ---------------\n" EvalCode "\n-------------\n"

 

 

Re: EVAL_ Command
SystemAdmin - Mon Aug 17 09:15:34 EDT 2009

llandale - Sun Aug 16 14:56:46 EDT 2009

Yes, you can send a script to eval_ and it will run it in its own context. 'Own Context' means the eval script will not have access to any of the main scripts variables nor functions; which likewise means you cannot pass in any sort of 'Module' et tal handle. If the eval DXL wants to deal with a module you'll need to pass that name in, and the eval script must open it.

When the eval DXL ends it will pass back to the main DXL the last string value of any 'return_' string used in the eval DXL. That 'return_' function does not mean 'stop now and return this string'; it means 'return this string when this DXL ends naturally'.

See below for a Demo. Notice that you need to escape double quotes in the string: "\"", as well as escape the slash character (not shown "\\"). Note my use of sibling 'checkDXL' which interprets the DXL (without actually running it) and traps typos before sending it off to run. Very useful.

Some of the real clever folks here may have found a use for eval_, but the only use I've found is for functions that use later versions of DXL features, such as the 'AttrDef' 'description' property: ad.description, which will generate DXL error when run in old DOORS versions. If I write a eval_ string to fetch the desription, I can trap and handle (in this case ignore) any DXL errors, and the code works for old versions.
 

  • Louie


Now there IS a use for 'evalTop_' which lets you put variables and functions in the DXL top context, making them available for other DXL programs to use. Haven't actually found a use for that, but surely there are some. Perhaps you want to overload the 'print' function such that instead of outputing to the DXL pane, it outputs it to a file.

 

 

// eval_ demo
/*
run from any current module,preferably one with deleted objects
*/
 
string    NameMod = fullName(current Module)
 
string  EvalCode =
"Module mod = read(\"" NameMod "\", false)
Object  obj
int     Count = 0
if (confirm(\"Count displayed objects only?\"))
{  for obj in mod do  Count++
   return_(\"Number Displayed objects = \" Count \"\")
}
else
{  for obj in entire mod do Count++
   return_(\"Number of All objects = \" Count \"\")
}
// close(mod) // Interesting, this will close the main open module
"  // end definition of string EvalCode
 
string ErrMess = checkDXL(EvalCode)
if (!null ErrMess)
{   print "Error in EvalCode ======\n" ErrMess 
   print "-------------\n" EvalCode "\n=============\n"
}
else
 
{  string Returned
   noError
   if (confirm("Introduce DXL Errors"))
        Returned = eval_("xx = yy\n" EvalCode)
   else Returned = eval_(EvalCode)
   ErrMess = lastError
   if (!null ErrMess)
        print "====ErrMess in EvalCode ===\n" ErrMess "=========\n"
   else print "Returned Code =========\n" Returned "\n=============\n"
 
}
// print "EvalCode ---------------\n" EvalCode "\n-------------\n"

 

 

Thank you for the reply. Here is what I'm trying to do:

I have a dxl script with a GUI. If the user clicks a certain button on the GUI I'd like to run another scipt. This other script is called Run_Report.dxl. It is in the same directory as the running script. How would I use the eval_ command to run the script that is contained in the Run_Report.dxl file?

Thank you again for the help.

David Schwartz

Re: EVAL_ Command
llandale - Mon Aug 17 10:05:29 EDT 2009

SystemAdmin - Mon Aug 17 09:15:34 EDT 2009
Thank you for the reply. Here is what I'm trying to do:

I have a dxl script with a GUI. If the user clicks a certain button on the GUI I'd like to run another scipt. This other script is called Run_Report.dxl. It is in the same directory as the running script. How would I use the eval_ command to run the script that is contained in the Run_Report.dxl file?

Thank you again for the help.

David Schwartz

I don't know how a DXL can figure out the name and windows path of its own file. You can generate an error or use dxlHere(), but it tells you the relative path.

If you do know the exact path to the file, you can
eval_("#include <c:\MyFolder\MyDXL\MyOtherFile.dxl>")

But it will wait for the other script to end before returning, as will simply issuing the #include statement in that certain button's callback function.

  • Louie

Re: EVAL_ Command
SystemAdmin - Mon Aug 17 10:30:20 EDT 2009

llandale - Mon Aug 17 10:05:29 EDT 2009
I don't know how a DXL can figure out the name and windows path of its own file. You can generate an error or use dxlHere(), but it tells you the relative path.

If you do know the exact path to the file, you can
eval_("#include <c:\MyFolder\MyDXL\MyOtherFile.dxl>")

But it will wait for the other script to end before returning, as will simply issuing the #include statement in that certain button's callback function.

  • Louie

I'm sorry for being such a novice at DXl. here is what I did. I tooke the command you posted and put in the name of my file. Here is the command, verbatim, as it is in my script:

eval_("#include <c:\DXL\Pass_Fail_Counter.dxl>")

When I try to run the script from the DXL Editor windoe I get the following error message:

badly formed token ("#include)

Thanks again for the help.

David Schwartz

Re: EVAL_ Command
llandale - Mon Aug 17 12:02:47 EDT 2009

SystemAdmin - Mon Aug 17 10:30:20 EDT 2009
I'm sorry for being such a novice at DXl. here is what I did. I tooke the command you posted and put in the name of my file. Here is the command, verbatim, as it is in my script:

eval_("#include <c:\DXL\Pass_Fail_Counter.dxl>")

When I try to run the script from the DXL Editor windoe I get the following error message:

badly formed token ("#include)

Thanks again for the help.

David Schwartz

Your #include statement is first a string, and then becomes a DXL command. That string has \ slashes; either change them to / slashes or escape them \\.

eval_("#include <c:\\DXL\\Pass_Fail_Counter.dxl>")
eval_("#include <c:/DXL/Pass_Fail_Counter.dxl>")

  • Louie

I now notice that the eval_ DXL environment is not that same as the GUI. For example you cannot refer to the 'obj' which is predefined for layouts and attrDxL.

if (null obj)
return("")
else return(identifier(obj))

works in the GUI, but not in eval_. Hopefully someone else will comment on that.

Re: EVAL_ Command
SystemAdmin - Mon Aug 17 12:07:42 EDT 2009

llandale - Mon Aug 17 12:02:47 EDT 2009
Your #include statement is first a string, and then becomes a DXL command. That string has \ slashes; either change them to / slashes or escape them \\.

eval_("#include <c:\\DXL\\Pass_Fail_Counter.dxl>")
eval_("#include <c:/DXL/Pass_Fail_Counter.dxl>")

  • Louie

I now notice that the eval_ DXL environment is not that same as the GUI. For example you cannot refer to the 'obj' which is predefined for layouts and attrDxL.

if (null obj)
return("")
else return(identifier(obj))

works in the GUI, but not in eval_. Hopefully someone else will comment on that.

Thank you very much! I changed each backslash to a double backslash and it worked.

David Schwartz

Re: EVAL_ Command
jsarkic1 - Mon Aug 24 12:33:04 EDT 2009

llandale - Mon Aug 17 12:02:47 EDT 2009
Your #include statement is first a string, and then becomes a DXL command. That string has \ slashes; either change them to / slashes or escape them \\.

eval_("#include <c:\\DXL\\Pass_Fail_Counter.dxl>")
eval_("#include <c:/DXL/Pass_Fail_Counter.dxl>")

  • Louie

I now notice that the eval_ DXL environment is not that same as the GUI. For example you cannot refer to the 'obj' which is predefined for layouts and attrDxL.

if (null obj)
return("")
else return(identifier(obj))

works in the GUI, but not in eval_. Hopefully someone else will comment on that.

Hi Louie.

The way around the obj issue is to pass all the information that you need to the eval_ perm as follows:

eval_("int objAbsNo = " obj."Absolute Number" "\nstring attrDXLName = \"" attrDXLName "\"\n#include <c:\\temp\\dxlTest.dxl>")

In your dxl file (dxlTest.dxl in my example) you can use the passed-in information as follows:

Object obj = object(objAbsNo)
obj.attrDXLName = identifier(obj) ""

For this code I made a Text type attribute DXL where I placed the eval_ statement.